package com.etone.mina.codec;

import java.nio.charset.Charset;

public class Generator extends TestCase{

	Charset charset = Charset.forName("UTF8");
	
	public void generate(){
		
		TableStream ts = new TableStream();
		
		ts.setName("CGI");
		ts.setLen("50");
		ts.setBodyData("jasic,bassice,11,23,aa,33,");
		
		byte name[] = new byte[64];
		byte len[] = new byte[16];
		
		fillAarray(name, "\0".getBytes()[0]);
		
		byte[] name_temp = ts.getName().getBytes(Charset.defaultCharset());
		byte[] len_temp = ts.getLen().getBytes();
		
		System.arraycopy(name_temp, 0, name, 0, name_temp.length);
		System.arraycopy(len_temp, 0, len, 0, len_temp.length);
		
		System.out.println(new String(name));
		System.out.println(name_temp.length);
		System.out.println(new String(name_temp));
		
		System.out.println(printByte(name));
		
		System.out.println(byte2BinaryString("\0".getBytes()));

	}
	
	public static void main(String[] args) {
		new Generator().generate();
	}
	
	public static String byte2BinaryString(byte b[]){
		String value = "";
		for(byte bb : b){
			value += Integer.toString(bb, 2);
		}
		
		return value;
		
	}
	
	public static byte[] fillAarray(byte array[], byte object){
		
		for(int i=0;i<array.length; i++){
			array[i] = object;
		}
		
		return array;
	}
	

	public static String printByte(byte[] b){
		
		String value = "";
		for(byte bb : b){
			value += bb;
		}
		
		return value;
	}
	
	{
//		Integer.toBinaryString(i);
	}
	public static String stringToHexString(String strPart) {
        String hexString = "";
        for (int i = 0; i < strPart.length(); i++) {
            int ch = (int) strPart.charAt(i);
            String strHex = Integer.toHexString(ch);
            hexString = hexString + strHex;
        }
        return hexString;
    }
}
